package user;

import java.sql.*;

public class DisplayRestaurantPage
{
	/*
	public static String getRestaurantList()
	{
		DBConnector db = DBConnector.getDBConnector();
		StringBuffer sBuf = new StringBuffer();	
		
		try {			
			db.prepareStatement("select rest_name, rest_link from restaurant");
			ResultSet rs = db.queryPstmt();			
			
			while (rs.next()){
				sBuf.append("<TR><TD align='center' width='50%'><div align='center'>" +
						"<A href='" + rs.getString(2) + ".jsp' " +
						"target=_blank class='16 16'>" +
						"<em><strong>" + rs.getString(1)+ "</strong></em></A></div></TD></TR>");
			}
			
			return sBuf.toString();
		}catch (SQLException ex){
			ex.printStackTrace();
			return "";
		}finally{
		}
	}
	*/
	
	//Retrieve the list of all the restaurant, display them in the dropdown menu in index.jsp
	public static String getRestaurantListItems()
	{
		DBConnector db = DBConnector.getDBConnector();
		StringBuffer sBuf = new StringBuffer();	
		
		try {			
			db.prepareStatement("select rest_name, rest_ID from restaurant");
			ResultSet rs = db.queryPstmt();
			
			if (rs != null)
			{
				while (rs.next()){
					sBuf.append("<option value='" + rs.getString(2) + "'>" + rs.getString(1) + "</option>");
				}
			}
			
			return sBuf.toString();
		}catch (SQLException ex){
			ex.printStackTrace();
			return "";
		}finally{			
		}
	}
	
	//Given the restaurant ID, retrieve restaurant name of the selected restaurant
	public static String getRestaurantName()
	{
		DBConnector db = DBConnector.getDBConnector();
		StringBuffer sBuf = new StringBuffer();	
		String Rest_ID = RestaurantQuery.getRestaurantSelected();
		
		try {			
			String statement = "select rest_name from restaurant where rest_ID = " + Rest_ID;
			db.prepareStatement(statement);
			ResultSet rs = db.queryPstmt();
			
			while (rs.next()){
				sBuf.append(rs.getString(1));
			}
			
			return sBuf.toString();
		}catch (SQLException ex){
			ex.printStackTrace();
			return "";
		}finally{		
		}
	}
	
	//Given the restaurant ID, retrieve restaurant address of the selected restaurant
	public static String getRestaurantAddress()
	{
		DBConnector db = DBConnector.getDBConnector();
		StringBuffer sBuf = new StringBuffer();	
		String Rest_ID = RestaurantQuery.getRestaurantSelected();
		
		try {	
			String statement = "select rest_address from restaurant where rest_ID = " + Rest_ID;
			db.prepareStatement(statement);
			ResultSet rs = db.queryPstmt();
			
			while (rs.next()){
				sBuf.append(rs.getString(1));
			}
			
			return sBuf.toString();
		}catch (SQLException ex){
			ex.printStackTrace();
			return "";
		}finally{			
		}
	}
	
	//Given the restaurant ID, retrieve restaurant phone number of the selected restaurant
	public static String getRestaurantPhoneNum()
	{
		DBConnector db = DBConnector.getDBConnector();
		StringBuffer sBuf = new StringBuffer();	
		String Rest_ID = RestaurantQuery.getRestaurantSelected();
		
		try {			
			String statement = "select rest_phone from restaurant where rest_ID = " + Rest_ID;
			db.prepareStatement(statement);
			ResultSet rs = db.queryPstmt();
			
			while (rs.next()){
				sBuf.append(rs.getString(1));
			}
			
			return sBuf.toString();
		}catch (SQLException ex){
			ex.printStackTrace();
			return "";
		}finally{
		}
	}	
	
	//Given the restaurant ID, retrieve restaurant open/close time of the selected restaurant
	public static String getRestaurantOpenCloseTime()
	{
		DBConnector db = DBConnector.getDBConnector();
		StringBuffer sBuf = new StringBuffer();	
		String Rest_ID = RestaurantQuery.getRestaurantSelected();
		
		try {			
			String statement = "select rest_open_time, rest_close_time from restaurant where rest_ID = " + Rest_ID;
			db.prepareStatement(statement);
			ResultSet rs = db.queryPstmt();
			
			while (rs.next()){
				sBuf.append(rs.getString(1) + " - " + rs.getString(2));
			}
			
			return sBuf.toString();
		}catch (SQLException ex){
			ex.printStackTrace();
			return "";
		}finally{
		}
	}
	
	//Given the restaurant ID, retrieve restaurant logo of the selected restaurant
	public static String getRestaurantLogo()
	{
		DBConnector db = DBConnector.getDBConnector();
		StringBuffer sBuf = new StringBuffer();	
		String Rest_ID = RestaurantQuery.getRestaurantSelected();
		
		try {			
			String statement = "select rest_pic_link from restaurant where rest_ID = " + Rest_ID;
			db.prepareStatement(statement);
			ResultSet rs = db.queryPstmt();
			
			while (rs.next()){
				sBuf.append("<IMG id='Mcdonalds_Logo' src='Pics/" + rs.getString(1) + "' width=150 height='150'>");
			}
			
			return sBuf.toString();
		}catch (SQLException ex){
			ex.printStackTrace();
			return "";
		}finally{
		}
	}
	
	
}
